﻿using System;
using System.Collections.Generic;
using System.Text;
using Bussiness.Model;
using Bussiness.Service.Base;
using Bussiness.Service.Impl;

namespace Bussiness.Service.Factory {
    public class CategoryServiceUtil {

        public static Category FindCategory(long id)
        {
            return Service.FindById(id);
        }

        public static Category AddCategory(Category category)
        {
            return Service.MakePersistance(category);
        }

        public static void DeleteCategory(long categoryId)
        {
            Service.MakeTransient(Service.FindById(categoryId));
            Service.Flush();
        }

        public static void DeleteCategory(Category category)
        {
            Service.MakeTransient(category);
            Service.Flush();
        }

        public static IList<Category> FindAll()
        {
            return Service.FindAll();
        }

        public static IList<Category> FindRootCategory()
        {
            return Service.GetRootCategorys();
        }

        private static ICategoryService _service;
        private static ICategoryService Service
        {
            get { return _service ?? (_service = new CategoryServiceImpl()); }
        }

    }
}
